# -*- coding: utf-8 -*-
__author__ = 'xuliliang'
# @Time    : 2018/2/1 下午1:59
# @Author  : 'xuliliang'
# @Email   : xuliliang@u51.com
# @File    : page.py
# @Software: PyCharm



LIST = []
for i in range(1,236):
	LIST.append(i)

def page(request):
	per_page = 15 #每页显示条数
	current_page = request.GET.get('p',1)
	current_page =  int(current_page) #当前页码
	total_count,yushu = divmod(len(LIST),per_page) #总页数,如果余数为真就+1
	if yushu:
		total_count += 1

	start_index = (current_page - 1) * per_page # 起始页码
	end_index = current_page * per_page  #结束页码

	page_list = []
	start_index = current_page - 5
	end_index = current_page + 5
	for i in range(start_index,end_index):
		if i == current_page:
			temp = '<a class="page active" href="/blog/page?p=%s">%s</a>' % (i,i)
		else:
			temp = '<a  href="/blog/page?p=%s" class="page">%s</a>' % (i, i)
		page_list.append(temp)

	page_str = ''.join(page_list)
	page_str = mark_safe(page_str)

	# data = LIST[0:10]
	# data = LIST[10:20]
	data = LIST[start_index:end_index]

	return  render(request,'blog/page.html',{'li':data,'page_str':page_str})